package repositories

import (
	"pegasus/models"
	"pegasus/utils"

	"github.com/go-xorm/xorm"
)

//LogRepo 用户登录日志激励
type LogRepo struct {
	logger utils.ILogger
	engine *xorm.Engine
}

//NewLogRepo 返回1个LogRepo
func NewLogRepo(il utils.ILogger, e *xorm.Engine) *LogRepo {
	return &LogRepo{
		logger: il,
		engine: e,
	}
}

//AddLogin 添加登录日志
func (lr *LogRepo) AddLogin(user int64) {
	err := utils.Transaction(lr.engine, func(si *xorm.Session) error {
		bean := &models.UserLoginBean{UserID: user}
		_, err := si.Insert(bean)
		return err
	})
	if err != nil {
		lr.logger.Error(err)
	}
}

//AddCharacter 添加角色登录日志
func (lr *LogRepo) AddCharacter(character int64) {
	err := utils.Transaction(lr.engine, func(si *xorm.Session) error {
		bean := &models.CharacterLoginBean{CharacterID: character}
		_, err := si.Insert(bean)
		return err
	})
	if err != nil {
		lr.logger.Error(err)
	}
}
